import java.util.Scanner;

public class test1 {
    //力扣 202 快乐数
    public static void main(String[] args) {

//        System.out.println(getNum(n));
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int slow = getNum2(n);
        int fast = getNum2(getNum2(n));

        while (slow!=fast){
            slow = getNum2(slow);
            fast = getNum2(fast);
            fast = getNum2(fast);

        }
        if(slow==1){
            System.out.println("true");

        }else{
            System.out.println("false");
        }

    }

    private static int getNum(int n) {
        int num = 0;
        while (n!=0){
            int t = (n%10)*(n%10);
            num+=t;
            n/=10;

        }
        return num;
    }

    private static int getNum2(int n) {
        if(n==1){
            return 1;
        }
        int num = 0;

        while (n!=0) {
            int t = (n%10)*(n%10);
            num+=t;
            n/=10;
        }

        return num;
    }

}
//abcdefghijklmnopqrstuvwxyz
//abcdefghijklmnopqrstuvwxyz
//abcdefghijklmnopqrstuvwxyz
